package sjtu.ist.warehouse4ws.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import sjtu.ist.warehouse4ws.model.CustDomainmodel;
import sjtu.ist.warehouse4ws.model.Domainmodel;
import sjtu.ist.warehouse4ws.service.DomainModelService;
import sjtu.ist.warehouse4ws.service.cust.CustDomainModelService;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.struts2.json.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ShowDomainModelListAction extends ActionSupport {
	private DomainModelService domainModelService;
	private CustDomainModelService custDomainModelService;
	private List<Domainmodel> domainModelList = new ArrayList<Domainmodel>();
	private String gid;
	private String vid;
//	public String execute() {
//		return SUCCESS;
//	}


	
	public void setCustDomainModelService(
			CustDomainModelService custDomainModelService) {
		this.custDomainModelService = custDomainModelService;
	}

	//获得DomainModel列表
	public String showDomainModelList(){
		
		Subject currentUser = SecurityUtils.getSubject();		
		
		if(!currentUser.hasRole("superadmin"))
		{
			List<CustDomainmodel> templist=custDomainModelService.getCustDomainModelList();
			this.domainModelList = new ArrayList<Domainmodel>();
			for(Domainmodel d : templist){
				//if(privilegeService.checkPrivilege(d.getFileId(),userCompany,userType, "read")){
					domainModelList.add(d);
				//}
			}
		}
		else
		{
			//domainModelList=domainModelService.getDomainModelList();
			domainModelList=domainModelService.getDomainmodelListByGroupAndVersion(gid,vid);
		}
		return SUCCESS;
	}
	
	@JSON(name = "totalDomainModel")
	public int getTotalDomainModel() {
		return this.domainModelList.size();
	}

	@JSON(name = "DomainModel")
	public List<Domainmodel> getDomainModelList() {
		return this.domainModelList;
	}
	
	// 注入DomainModelService
	public void setDomainModelService(DomainModelService domainModelService) {
		this.domainModelService = domainModelService;
	}

	public String getGid() {
		return gid;
	}

	public void setGid(String gid) {
		this.gid = gid;
	}

	public String getVid() {
		return vid;
	}

	public void setVid(String vid) {
		this.vid = vid;
	}
	
}